# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=python-time-machine
pkgver=2.13.0
pkgrel=1
pkgdesc='Travel through time in your tests'
arch=('loong64' 'x86_64')
url='https://github.com/adamchainz/time-machine'
license=('MIT')
depends=(
  'python'
  'python-dateutil'
)
makedepends=(
  'git'
  'python-build'
  'python-installer'
  'python-setuptools'
  'python-wheel'
)
checkdepends=('python-pytest' 'python-pytest-randomly')
optdepends=('python-pytest: for pytest plugin')
_commit='b31371c4e47aa5c7bc22cd26dd273822e6791607'
source=("$pkgname::git+$url#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

build() {
  cd "$pkgname"

  python -m build --wheel --no-isolation
}

check() {
  cd "$pkgname"

  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  # install to temporary directory
  python -m installer --destdir="$(pwd)/tmp_install" dist/*.whl

  PYTHONPATH="$(pwd)/tmp_install$site_packages" \
    pytest -v
}

package() {
  cd "$pkgname"

  python -m installer --destdir="$pkgdir" dist/*.whl

  # symlink license file
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir/usr/share/licenses/$pkgname"
  ln -s "$site_packages/time_machine-$pkgver.dist-info/LICENSE" \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
